<template>
  <div class="ele-body" v-loading="loading">
    <el-card shadow="none">
      <template #header>
        <div class="name">{{ info.customer_name }}</div>
      </template>
      <template>
        <div class="top">
          <div class="bottom">
            <div v-for="item in info.histories" :key="item.id" class="list">{{ item.status_text }}</div>
          </div>
          <div class="closeWork">
            <el-button  type="primary" v-if="info.btn_accept" @click="acceptTask">接受</el-button>
            <el-button  type="primary" v-if="info.btn_start" @click="startTask">开始</el-button>
            <el-button
                       type="primary" v-if="info.btn_complete" @click="completeTask">完成
            </el-button>
          </div>
        </div>
      </template>
    </el-card>

    <!-- 工单信息 -->
    <div class="info-content">
      <el-card class="content-left" shadow="never">
        <div class="left-top">
          <div>巡检编号：{{ info.number }}</div>
          <!--<el-button size="mini" type="primary">编辑</el-button>-->
        </div>
        <div class="left-bottom-info">
          <div>客户： {{ info.customer_name}}</div>
          <div>联系人： <span >{{ info.customer_user_name }}</span></div>
          <div>电话： {{ info.customer_user_telephone }}</div>
          <div>地址：
            <img alt="" src="../../../../assets/work_info/icon_map@2x.png" style="width: 13px;height: 16px;">
            <span style="color:var( --color-primary);margin-left: 5px;">
              {{ info.customer_address }}
            </span>
          </div>
          <div>计划时间： {{ info.plan_at }}</div>
          <div>创建时间： {{ info.create_time }}</div>
          <div>创建人： <span>{{ info.create_user_name}}</span></div>
          <div>状态：
            <el-button round size="mini" type="primary">{{ info.status_text }}</el-button>
          </div>
          <div>负责人： <span >{{ info.user_name }}</span></div>
          <div>描述： {{ info.description }}</div>
        </div>
      </el-card>
      <el-card class="right" shadow="never">
        <el-tabs v-model="tabsActive">
          <el-tab-pane label="动态信息" name="dtxx">
            <DynamicInfo ref="dynamicInfo" :logs="logs"/>
          </el-tab-pane>
          <el-tab-pane label="回执信息" name="hzxx" v-if="info.complete_at">
            <return_info  :info="info"/>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
    <completeTask ref="completeTask" :visible.sync="visible" :id="id" @done="done" @cancel="cancel"/>
  </div>
</template>

<script>
import DynamicInfo from "./components/dynamic_info.vue"
import completeTask from "@/views/inspection/task/info/components/completeTask.vue";
import return_info from "@/views/inspection/task/info/components/return_info.vue";
// import { removePageTab } from '@/utils/page-tab-util'
import {mapGetters} from "vuex";


export default {
  components: {
    return_info,
    DynamicInfo,
    completeTask,
  },
  data() {
    return {
      closeLoading: false,
      //回访对话框
      returnVisible: false,
      //审核对话框
      visible: false,
      loading: false,
      id: null,
      tabsActive: "dtxx",
      info: {},
      logs: [],
      //审核信息
      auditInfo: {},
      //回访信息
      returnInfo: {},
      //回执信息
      receiptInfo: {},
    }
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  mounted() {
    this.getInfo();
  },
  created() {
    this.id = this.$route.query.id;
  },
  methods: {
    //打开填写回执
    toReceipt() {
      this.$refs.addReceipt.showDialog(this.id);
    },
    //取消
    cancel() {
      this.visible = false
    },
    //完成
    done(id) {
      if (id) {
        this.id = id
      }
      this.visible = false
      this.getInfo();
    },
    //接受任务
    acceptTask() {
      this.$http.post(`/pollings/${this.id}/accept`).then(res => {
        if (res.data.code === 0) {
          this.getInfo()
          this.$forceUpdate()
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.loading = false
        this.$message.error(e.message);
      });
    },
    startTask() {
      this.$http.post(`/pollings/${this.id}/start`).then(res => {
        if (res.data.code === 0) {
          this.getInfo()
          this.$forceUpdate()
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.loading = false
        this.$message.error(e.message);
      });
    },
    completeTask() {
      this.visible=true
    },
    // 获取详情
    getInfo() {
      this.loading = true
      this.$http.get('/pollings/' + this.id).then(res => {
        if (res.data.code === 0) {
          this.info = res.data.data;
          this.logs = res.data.data.histories;
          this.$forceUpdate()
          this.loading = false
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.loading = false
        this.$message.error(e.message);
      });
    }
  }
}
</script>

<style lang="scss" scoped>


.work_info {
  width: 96%;
  margin: 50px auto 0;
}


.top {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  justify-content: space-between;
}

.bottom {
  display: flex;
  height: 100%;
  align-items:center;

  .list {
    width: 108px;
    height: 35px;
    text-align: center;
    line-height: 38px;
    box-shadow: 0 1px 1px rgba(0,0,0,.05), 0 2px 6px 0 rgba(0,0,0,.045);
    background-color: var(--color-primary-1);
    color: var(--color-primary);
    position: relative;
    margin: 0 15px 0 10px;
    letter-spacing: 5px;
    font-weight: bold;
    border-left: 4px solid var(--color-primary);
    border-radius: 4px 2px 2px 4px;
    &::after{
      content: " ";
      width: 0;
      height: 0;
      position: absolute;
      top:-1px;
      right: -7px;
      display: inline-block;
      border-color: transparent transparent transparent var(--color-primary-1);
      border-style: solid;
      border-width: 18px 0 18px 8px;
    }
  }
}


.info-content {
  height: calc(100vh - 268px);
  margin-top: 15px;
  display: flex;
  justify-content: space-between;

  .el-card + .el-card {
    margin-top: 0;
  }

  .content-left {
    width: 30%;
    box-sizing: border-box;
    overflow: auto;

    .left-top {
      font-size: 14px;
      color: #000000;
      font-weight: 600;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 10px;
      border-bottom: 2px solid #eeeeee;
      box-sizing: border-box;
    }

    .left-bottom-info {
      font-size: 14px;

      div {
        padding: 10px 5px;
      }
    }
  }

  .right {
    //width: 68%;
    margin-left: 15px;
    flex: 1;
    overflow: auto;
  }
}
</style>

